//
//  YUTextField.m
//  百思不得
//
//  Created by 宋禹奇 on 15/9/5.
//  Copyright (c) 2015年 宋禹奇. All rights reserved.
//

#import "YUTextField.h"
#import <objc/runtime.h>

static NSString * const YUPlacerholderColorKeyPath = @"_placeholderLabel.textColor";

@implementation YUTextField


+ (void)initialize{
   // [self getIvars];
}

+ (void)getIvars{
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([UITextField class], &count);
    
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        
       // YULog(@"%s,%s",ivar_getName(ivar),ivar_getTypeEncoding(ivar));
    }
    free(ivars);
}

+ (void)getPropertise{
    unsigned int count = 0;
    
    objc_property_t *properties = class_copyPropertyList([UITextField class], &count);
    
    for (int i = 0; i < count; i++) {
        objc_property_t property = properties[i];
        
       // YULog(@"%s  <---------->   %s",property_getName(property),property_getAttributes(property));
    }
    free(properties);
}

- (void)awakeFromNib{
    //设置光标颜色和文字颜色一致
    self.tintColor = self.textColor;
    //不成为第一响应者
    [self resignFirstResponder];
}

- (BOOL)becomeFirstResponder{
    [self setValue:self.textColor forKeyPath:YUPlacerholderColorKeyPath];
    return [super becomeFirstResponder];
}

- (BOOL)resignFirstResponder{
    [self setValue:[UIColor grayColor] forKeyPath:YUPlacerholderColorKeyPath];
    return [super resignFirstResponder];
}

//- (void)drawPlaceholderInRect:(CGRect)rect{
//    [self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{
//                                                    NSForegroundColorAttributeName : [UIColor grayColor],
//                                                    NSFontAttributeName : self.font
//                                                    }];
//}

@end
